<template>
  <div id="guide">
    <div class="guide-list">
      <!-- 内容列表 -->
      <ul class="content" v-if="list.length != 0">
        <li class="item" v-for="(item,index) in list" :key="index" @click="navDetail(index)">
          <md-cell-item :title="item.title" :brief="item.add_time">
            <span class="icon" slot="left"></span>
          </md-cell-item>
        </li>
      </ul>
      <ul class="content" v-else>
        <li class="empty-list">暂无通知</li>
      </ul>
    </div>
  </div>
</template>

<script>
import { Toast, Dialog, CellItem } from "mand-mobile";
import https from "@/https";
import config from "@/config";
export default {
  components: {
    [Dialog.name]: Dialog,
    [CellItem.name]: CellItem
  },
  name: "communityInform",
  data() {
    return {
      list: []
    };
  },
  methods: {
    // 获取列表
    guideList() {
      Toast.loading("加载中...");
      let qid = this.$store.state.residentialType.qid
      let params = {
        qid
      };
      https
        .fetchPost(config.guideList, params)
        .then(res => {
          Toast.hide();
          if (res.data.code == 1) {
            let list = res.data.data.list;
            if (list.length != 0) {
              list.forEach(element => {
                element.add_time = this.dataFormat(element.add_time * 1000, 1);
              });
              this.list = list;
            } else {
              Toast.failed("目前没有办事指南");
            }
          } else {
            Toast.failed(res.data.msg);
          }
        })
        .catch(err => {
          Toast.hide();
          console.log(err);
        });
    },
    navDetail(index) {
      let qid = this.$store.state.residentialType.qid;
      let sid = this.list[index].sid;
      this.$router.push({
        path: "/communityGuideDetail",
        query: { qid: qid, sid: sid }
      });
    },
    // 时间戳转换
    dataFormat(num, type) {
      var dd = new Date(num);
      var y = dd.getFullYear();
      var m = dd.getMonth() + 1;
      var d = dd.getDate();
      var h = dd.getHours();
      var i = dd.getMinutes();
      var s = dd.getSeconds();
      m = m < 10 ? "0" + m : m;
      d = d < 10 ? "0" + d : d;
      h = h < 10 ? "0" + h : h;
      i = i < 10 ? "0" + i : i;
      s = s < 10 ? "0" + s : s;
      if (type == 1) {
        return y + "-" + m + "-" + d + " " + h + ":" + i + ":" + s;
      } else {
        return y + "-" + m + "-" + d + " " + h + ":" + i;
      }
    }
  },
  created() {
    this.guideList();
  }
};
</script>

<style  lang="scss" scoped>
$themeColor: #444444;
$themeGold: #d7b987;
#guide {
  .guide-list {
    height: 100vh;
    padding: 0 40px;
    .item {
      .icon {
        display: block;
        width: 88px;
        height: 88px;
        border-radius: 50%;
        background: #fff url("/../static/images/community/guide.png") no-repeat
          center center;
        background-size: 80%;
        border: 1px solid #eee;
      }
    }
  }
  .empty-list {
    padding-top: 100px;
    font-size: 30px;
    color: #666;
    text-align: center;
  }

}
</style>
